package com.changan.user.controller;


import com.changan.exception.BusinessException;
import com.changan.response.Result;
import com.changan.response.ResultCode;
import com.changan.user.entity.User;
import com.changan.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author ange
 * @since 2020-09-05
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "查询单个用户",notes = "根据ID查询用户信息")
    @GetMapping("{id}")
    public Result getUserById(@PathVariable("id") Integer id){
        User user = userService.getById(id);
        if(user==null){
            throw new BusinessException(ResultCode.USER_NOT_FOUND_EXCEPTION.getCode(),ResultCode.USER_NOT_FOUND_EXCEPTION.getMessage());
        }
        return Result.ok().data("user",user);
    }

    @ApiOperation(value = "用户登录",notes = "根据手机号和密码查询用户进行登录")
    @GetMapping("/login")
    public Result login(@RequestParam("mobile") String mobile,@RequestParam("mobile_psw") String mobile_psw){

        return Result.ok();
    }
}

